package com.ruoyi.student.service.impl;

import com.ruoyi.student.domain.vo.CourseSchedulingIinquiryVo;
import com.ruoyi.student.mapper.StudentInfoMapper;
import com.ruoyi.student.service.ICourseSchedulingIinquiryService;
import com.ruoyi.teacher.service.IteacherService;
import com.ruoyi.trainingManagement.domain.ClassScheduleDetailed;
import com.ruoyi.trainingManagement.domain.CourseScheduleDetails;
import com.ruoyi.trainingManagement.mapper.ClassScheduleDetailedMapper;
import com.ruoyi.trainingManagement.mapper.CourseScheduleDetailsMapper;
import com.ruoyi.trainingManagement.mapper.CourseStudentInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class CourseSchedulingIinquiryServiceImpl implements ICourseSchedulingIinquiryService {
    @Autowired
    private StudentInfoMapper StudentInfoMapper;
    @Autowired
    private CourseStudentInfoMapper courseStudentInfoMapper;
    @Autowired
    private CourseScheduleDetailsMapper courseScheduleDetailsMapper;
    @Autowired
    private ClassScheduleDetailedMapper classScheduleDetailedMapper;
    @Autowired
    private IteacherService teacherServiceImpl;
    @Override
    public List<CourseSchedulingIinquiryVo> selectCourseSchedulingIinquiryList(String trainingProgramId){
        List<String> studentInfos = StudentInfoMapper.selectStudentIdListByTrainingProgramId(trainingProgramId);

        System.out.println("获取到的名单为: " + studentInfos);
        List<String> courseScheduleDetailsIds = courseStudentInfoMapper.selectDistinctCourseScheduleIdsByStudentIds(studentInfos);
        System.out.println("获取到的排课ID为: " + courseScheduleDetailsIds);

        List<CourseSchedulingIinquiryVo> courseSchedulingIinquiryVos = new ArrayList<>();
        //遍历courseScheduleDetailsIds
        for (String courseScheduleDetailsId : courseScheduleDetailsIds) {
            CourseSchedulingIinquiryVo courseSchedulingIinquiryVo = new CourseSchedulingIinquiryVo();
            CourseScheduleDetails courseScheduleDetails  =courseScheduleDetailsMapper.selectById(courseScheduleDetailsId);
            List<ClassScheduleDetailed> classScheduleDetailes =classScheduleDetailedMapper.selectAllByCourseScheduleDetailsId(courseScheduleDetailsId);
            courseSchedulingIinquiryVo.setCourseScheduleDetails(courseScheduleDetails);
            courseSchedulingIinquiryVo.setClassScheduleDetailedList(classScheduleDetailes);
            courseSchedulingIinquiryVos.add(courseSchedulingIinquiryVo);
        }
        return courseSchedulingIinquiryVos;

    }
    /**通过课程班id获取学生名单，然后查询学生对应的已开课班级以及时间*/
    @Override
    public List<CourseSchedulingIinquiryVo> selectCourseSchedulingIinquiryListByClassId(String classId){
        List<String> studentIds = courseStudentInfoMapper.selectStudentIdsByCourseScheduleDetailsId(classId);
        System.out.println("获取到的名单为: " + studentIds);
        List<String> courseScheduleDetailsIds = courseStudentInfoMapper.selectDistinctCourseScheduleIdsByStudentIds(studentIds);
        System.out.println("获取到的排课ID为: " + courseScheduleDetailsIds);
        List<CourseSchedulingIinquiryVo> courseSchedulingIinquiryVos = new ArrayList<>();
        for (String courseScheduleDetailsId : courseScheduleDetailsIds) {
            CourseSchedulingIinquiryVo courseSchedulingIinquiryVo = new CourseSchedulingIinquiryVo();
            CourseScheduleDetails courseScheduleDetails  =courseScheduleDetailsMapper.selectById(courseScheduleDetailsId);
            List<ClassScheduleDetailed> classScheduleDetailes =classScheduleDetailedMapper.selectAllByCourseScheduleDetailsId(courseScheduleDetailsId);
            courseSchedulingIinquiryVo.setCourseScheduleDetails(courseScheduleDetails);
            courseSchedulingIinquiryVo.setClassScheduleDetailedList(classScheduleDetailes);
            courseSchedulingIinquiryVos.add(courseSchedulingIinquiryVo);
        }
        return courseSchedulingIinquiryVos;
    }

    /**根据学生ID获取对应课表*/
    @Override
    public List<CourseSchedulingIinquiryVo> selectCourseSchedulingIinquiryListByStudentId(String studentId){
        List<String> studentInfos = new ArrayList<>();
        studentInfos.add(studentId);
        List<String> courseScheduleDetailsIds = courseStudentInfoMapper.selectDistinctCourseScheduleIdsByStudentIds(studentInfos);
        System.out.println("获取到的排课ID为: " + courseScheduleDetailsIds);
        List<CourseSchedulingIinquiryVo> courseSchedulingIinquiryVos = new ArrayList<>();
        //遍历courseScheduleDetailsIds
        for (String courseScheduleDetailsId : courseScheduleDetailsIds) {
            CourseSchedulingIinquiryVo courseSchedulingIinquiryVo = new CourseSchedulingIinquiryVo();
            //resourceAvailabilityMapper.selectByResourceIdAndResourceType
            CourseScheduleDetails courseScheduleDetails  =courseScheduleDetailsMapper.selectById(courseScheduleDetailsId);
            List<ClassScheduleDetailed> classScheduleDetailes =classScheduleDetailedMapper.selectAllByCourseScheduleDetailsId(courseScheduleDetailsId);
            courseSchedulingIinquiryVo.setCourseScheduleDetails(courseScheduleDetails);
            courseSchedulingIinquiryVo.setClassScheduleDetailedList(classScheduleDetailes);
            courseSchedulingIinquiryVos.add(courseSchedulingIinquiryVo);
        }
        return courseSchedulingIinquiryVos;
    }


}
